package ch.ethz.fcl.metrofont;

class Point2D {
	private float x;
	private float y;

	public Point2D() {
		this.x = 0;
		this.y = 0;
	}

	public Point2D(float x, float y) {
		this.x = x;
		this.y = y;
	}

	public float distance(Object p) {
		double square = Math.pow(this.x - ((Point2D) p).getX(), 2)
				+ Math.pow(this.y - ((Point2D) p).getY(), 2);
		return (float) Math.sqrt(square);
	}

	public float getX() {
		return x;
	}

	public float getY() {
		return y;
	}

	public void setX(float x) {
		this.x = x;
	}

	public void setY(float y) {
		this.y = y;
	}

	@Override
	public String toString() {
		return "(" + x + ", " + y + ")";
	}

	public Point2D getPointAt(Point2D end, float rate) {
		float new_x = x + rate * (end.x - x);
		float new_y = y + rate * (end.y - y);

		return new Point2D(new_x, new_y);
	}
	
	public Point2D rotate(Point2D p, float angle) {
		float x = (float) (p.getX() * Math.cos(angle) - p.getY()
				* Math.sin(angle) - this.getX() * Math.cos(angle) + this.getY()
				* Math.sin(angle) + this.getX());
		float y = (float) (p.getX() * Math.sin(angle) + p.getY()
				* Math.cos(angle) - this.getX() * Math.sin(angle) - this.getY()
				* Math.cos(angle) + this.getY());
		return new Point2D(x, y);
	}
}
